var names = [
  "高哥",
  "潘俊雄",
  "李凌君",
  "董含超",
  "王晓婷",
  "焦汉龙",
  "李成泽",
  "王志文",
  "李家豪",
  "易家平",
  "刘礼炎",
  "刘赞",
  "张艺伟",
  "马飞",
  "郭晨昕",
  "刘文杰",
  "关浩",
  "康鼎皓",
  "门欣冉",
  "颜涵笑",
];
var aDiv = document.querySelectorAll(".box div");
var btn = document.querySelector("button");
var oInput = document.querySelector("input");
var tmp = "";
var t, mr;
var timeout = 0;
var flag = false;
for (var i = 0; i < names.length; i++) {
  aDiv[i].innerHTML = names[i];
  // console.log(aDiv[i].innerHTML);
  // console.log(names[i]);
}
setInterval(function () {
  var now = new Date();
  tmp = now.toLocaleDateString() + " " + now.toLocaleTimeString();
  oInput.value = tmp;
}, 1);
btn.onclick = function () {
  if (!flag) {
    flag = true;
    btn.innerHTML = "停止";
    t = setInterval(function () {
      mr = Math.floor(Math.random() * names.length);
      aDiv[timeout].style.backgroundColor = "greenyellow";
      aDiv[mr].style.backgroundColor = "brown";
      timeout = mr;
      // timeout = setTimeout(function () {
      //   aDiv[mr].style.backgroundColor = "greenyellow";
      // }, 50);
      // clearTimeout(timeout);
    }, 50);
  } else {
    flag = false;
    btn.innerHTML = "开始";
    clearInterval(t);
    // clearTimeout(timeout);
  }
};
